package com.health.web.controller.teahouse;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.health.common.annotation.Log;
import com.health.common.core.controller.BaseController;
import com.health.common.core.domain.AjaxResult;
import com.health.common.enums.BusinessType;
import com.health.teahouse.domain.Meats;
import com.health.teahouse.service.IMeatsService;
import com.health.common.utils.poi.ExcelUtil;
import com.health.common.core.page.TableDataInfo;

/**
 * 肉品信息Controller
 * 
 * @author yangzw
 * @date 2024-01-10
 */
@RestController
@RequestMapping("/teahouse/meats")
public class MeatsController extends BaseController
{
    @Autowired
    private IMeatsService meatsService;

    /**
     * 查询肉品信息列表
     */
    @PreAuthorize("@ss.hasPermi('teahouse:meats:list')")
    @GetMapping("/list")
    public TableDataInfo list(Meats meats)
    {
        startPage();
        List<Meats> list = meatsService.selectMeatsList(meats);
        return getDataTable(list);
    }

    /**
     * 导出肉品信息列表
     */
    @PreAuthorize("@ss.hasPermi('teahouse:meats:export')")
    @Log(title = "肉品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Meats meats)
    {
        List<Meats> list = meatsService.selectMeatsList(meats);
        ExcelUtil<Meats> util = new ExcelUtil<Meats>(Meats.class);
        util.exportExcel(response, list, "肉品信息数据");
    }

    /**
     * 获取肉品信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('teahouse:meats:query')")
    @GetMapping(value = "/{meatId}")
    public AjaxResult getInfo(@PathVariable("meatId") Long meatId)
    {
        return success(meatsService.selectMeatsByMeatId(meatId));
    }

    /**
     * 新增肉品信息
     */
    @PreAuthorize("@ss.hasPermi('teahouse:meats:add')")
    @Log(title = "肉品信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Meats meats)
    {
        return toAjax(meatsService.insertMeats(meats));
    }

    /**
     * 修改肉品信息
     */
    @PreAuthorize("@ss.hasPermi('teahouse:meats:edit')")
    @Log(title = "肉品信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Meats meats)
    {
        return toAjax(meatsService.updateMeats(meats));
    }

    /**
     * 删除肉品信息
     */
    @PreAuthorize("@ss.hasPermi('teahouse:meats:remove')")
    @Log(title = "肉品信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{meatIds}")
    public AjaxResult remove(@PathVariable Long[] meatIds)
    {
        return toAjax(meatsService.deleteMeatsByMeatIds(meatIds));
    }
}
